package br.com.ordersys.framework.db.metadata;

import java.util.HashMap;
import java.util.Map;

public class SchemaMetadata {
	private static Map<String, SchemaMetadata> schemas = new HashMap<String, SchemaMetadata>();
	private String name;
	private Map<String, TableMetadata> tables;

	public SchemaMetadata(String name) {
		this.name = name;
		tables = new HashMap<String, TableMetadata>();
	};

	public void addTable(TableMetadata tm) {
		tables.put(tm.getName(), tm);
		tm.setSchema(this);
	}

	public SchemaMetadata getByName(String schemaName) {
		SchemaMetadata sm = schemas.get(schemaName);

		if (sm == null) {
			sm = new SchemaMetadata(schemaName);
			schemas.put(schemaName, sm);
		}

		return sm;
	}

	public String getName() {
		return name;
	}
}
